import java.util.Date;

/**
 * Created by root on 27/02/14.
 */
public class CardDetails {

    private String cardOwner = "";

    private int cardNumber = 0;
    private int securityCode = 0;

    private Date begin = new Date(0);
    private Date expire = new Date(0);

    CardDetails(String cardOwner, int cardNumber, int securityCode, Date begin, Date expire ){
        updateDetails( cardOwner, cardNumber, securityCode, begin, expire );
    }

    /**
     * Charges the card described if the details are valid.
     *
     * @return True for successful charge and false for invalid details.
     */
    public boolean chargeCard(){
        if ( updateDetails(this.cardOwner, this.cardNumber, this.securityCode, this.begin, this.expire) ){
            // chargeCard
            return true;
        } else {
            return false;
        }
    }

    /**
     * Updates and verifies if the given card details are valid.
     *
     * @param cardOwner Name of the card owner.
     * @param cardNumber Card number.
     * @param securityCode Three digit security code.
     * @param begin Valid from date.
     * @param expire Expiry date.
     * @return True for valid details or otherwise false.
     */
    public boolean updateDetails( String cardOwner, int cardNumber, int securityCode, Date begin, Date expire ){
        int valid = 0; // If not 0 at the end of method, card details are invalid.

        valid += setCardOwner( cardOwner );
        valid += setCardNumber( cardNumber );
        valid += setSecurityCode( securityCode );
        valid += setBegin( begin );
        valid += setExpire( expire );

        if ( valid == 0 ){
            return true;
        } else {
            return false;
        }
    }

    // These setters return 0 for a valid value, and 1 for an invalid value.

    private int setCardOwner( String cardOwner ){
        boolean valid = true; // Place holder, replace with verify method.

        if ( valid ) {
            this.cardOwner = cardOwner;
            return 0;
        } else {
            return 1;
        }

    }

    private int setCardNumber( int cardNumber ){
        boolean valid = true; // Place holder, replace with verify method.

        if ( valid ) {
            this.cardNumber = cardNumber;
            return 0;
        } else {
            return 1;
        }
    }

    private int setSecurityCode( int securityCode ){
        boolean valid = true; // Place holder, replace with verify method.

        if ( valid ) {
            this.securityCode = securityCode;
            return 0;
        } else {
            return 1;
        }
    }

    private int setBegin( Date begin ){
        boolean valid = true; // Place holder, replace with verify method.

        if ( valid ) {
            this.begin = begin;
            return 0;
        } else {
            return 1;
        }
    }

    private int setExpire( Date expire ){
        boolean valid = true; // Place holder, replace with verify method.

        if ( valid ) {
            this.expire = expire;
            return 0;
        } else {
            return 1;
        }
    }
}
